         
/**
 * 
 *
 * @File name:  TFixedAssetsDao.java 
 * @Create on:  2011-10-30 20:01:346
 * @Author   :  谭翔
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
package com.boho.estates.report.dao;

import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;

import com.boho.estates.po.TFixedAssetsPO;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.CQExp;
import cn.boho.framework.po.Pager;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.utils.DateUtils;
            
/**
 * 【资产基本信息:T_FIXED_ASSETS】的Dao操作类
 * 
 */
public class TFixedAssetsDao extends DAO {
	/**
	* 查询所有【资产基本信息:T_FIXED_ASSETS】信息
	* @param con
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static List queryTFixedAssets(Connection con)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_FIXED_ASSETS", con);
		return list;
	}
	/**
	* 分页查询所有【资产基本信息:T_FIXED_ASSETS】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static ComboPager queryTFixedAssetsByPager(Connection con,Pager pager)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		return query.getDynaBeanMapComboPager("T_FIXED_ASSETS", pager,con);
	}
	
	
	/**
	* 根据条件查询【资产基本信息:T_FIXED_ASSETS|】信息
	* @param con
	* @param fixedAssetsName 资产名称
	* @param fixedAssetsType 资产类型
	* @param fixedAssetsNature 资产性质
	* @param createDateBegin 创建日期
	* @param createDateEnd 创建日期
	* @param createBy 创建人
	* @param isValid 是否有效
	* @return
	* @throws Exception
	* @date2011-10-31
	* @author 谭翔
	* 
	*/
	public static ComboPager queryTFixedAssetsByPager(Connection con,Pager pager,String fixedAssetsName,String fixedAssetsType,
			String fixedAssetsNature,String createDateBegin,String createDateEnd,String createBy,Integer isValid,
			String is_year,String is_mon,String dateStr,String dateFmt, String departIds)throws Exception{
		CQExp cqExp = CQExp.instance()
		.select("select B.FIXED_ASSETS_NAME,B.FIXED_ASSETS_TYPE,B.BRAND,B.FIXED_ASSETS_NATURE,B.CREATE_DATE,B.CREATE_BY, " +
				
				"B.BARCODE "+
				",B.DEPARTMENT_NO,B.STOCK_DATE,B.STOCK_PRICE,B.USE_YEAR,B.WARRANTY,B.SPECIFICATION, "+
				"b.SUPPLIERS_NO,B.FACTORY_NO,B.FA_STATUS, "+
				"B.STORED_IN,B.WITH_MANANGER,B.STOCK_QUANTITY  "+
				
				" from  T_FIXED_ASSETS_DETAIL B  ")
				.where()
				.filed(isValid == null ? null:"B.IS_VALID",CQExp.EQ,isValid);
		
			String oper_date = " B.CREATE_DATE ";
			if(0==isValid){
				oper_date = " B.UPDATE_DATE ";
			}
		
			if(("1").equals(is_year)){
				cqExp.str( " and date_format( "+oper_date+",'%Y') = '"+dateStr+"'  and B.FIXED_ASSETS_TYPE ='1' ");
			}else if(("1").equals(is_mon)){
				cqExp.str( " and date_format( "+oper_date+",'%Y-%m') = '"+dateStr+"' and B.FIXED_ASSETS_TYPE ='2' " );
			}
			
			
			else if(("1_2").equals(is_mon)){//本月规定资产增加或减少
				cqExp.str( " and date_format( "+oper_date+",'%Y-%m') = '"+dateStr+"' and B.FIXED_ASSETS_TYPE ='1' " );
			}
			
			else if(("all").equals(is_year)){//全部 新增或减少固定资产
				cqExp.str( "  and  B.FIXED_ASSETS_TYPE ='1' ");
			}
			else if(("y_2").equals(is_year)){//低值按年查询
				cqExp.str( " and date_format("+oper_date+",'%Y') = '"+dateStr+"'  and B.FIXED_ASSETS_TYPE ='2' ");
			}
			else if(("all_2").equals(is_year)){//全部 新增或减少低值
				cqExp.str( "  and  B.FIXED_ASSETS_TYPE ='2' ");
			}
			
			else {
				/*cqExp.filed(createDateBegin == null ? null:"B.CREATE_DATE",CQExp.GREATER_EQ,createDateBegin)
				.filed(createDateEnd == null ? null:"B.CREATE_DATE",CQExp.LESS_EQ,createDateEnd)*/
				if(createDateBegin != null){
					cqExp.str(" and date_format("+oper_date+",'%Y-%m-%d') >='"+createDateBegin+"'" );
				}
				if(createDateEnd != null){
					cqExp.str(" and date_format("+oper_date+",'%Y-%m-%d') <='"+createDateEnd+"'" );
				}
				cqExp.str(" and B.FIXED_ASSETS_TYPE ='1' ");
			}
			cqExp.str(" and GS_DEPARTMENT_NO in (" + departIds + ")");
		
		System.out.println(cqExp.getSql());
		return cqExp.getDynaBeanMapComboPager("T_FIXED_ASSETS",pager,con);
	}

	
	
	
	/**
	* 根据主键【资产基本信息编号:FIXED_ASSETS_NO|】获得信息
	* @param con
	* @param fixedAssetsNo 资产基本信息编号
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 谭翔
	*
	*/
	public static DynaBeanMap getTFixedAssetsByPk(Connection con,java.lang.Integer fixedAssetsNo)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS where  FIXED_ASSETS_NO=?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,fixedAssetsNo);
		dynaBeanMap = query.getDynaBeanMap("T_FIXED_ASSETS", con);
		return dynaBeanMap;
	}
	/**
	* 根据主键【资产基本信息编号:FIXED_ASSETS_NO|】获得PO对象
	* @param con
	* @param fixedAssetsNo 资产基本信息编号
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 谭翔
	*
	*/
	public static TFixedAssetsPO getTFixedAssetsPOByPk(Connection con,java.lang.Integer fixedAssetsNo)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS where  FIXED_ASSETS_NO=?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,fixedAssetsNo);
		dynaBeanMap = query.getDynaBeanMap("T_FIXED_ASSETS", con);
		if(dynaBeanMap!=null){
			TFixedAssetsPO tFixedAssetsPO = new TFixedAssetsPO();
			tFixedAssetsPO.setFixedAssetsNo(dynaBeanMap.get("FIXED_ASSETS_NO")==null?null:(Integer)dynaBeanMap.get("FIXED_ASSETS_NO"));
			tFixedAssetsPO.setFixedAssetsName(dynaBeanMap.get("FIXED_ASSETS_NAME")==null?null:(String)dynaBeanMap.get("FIXED_ASSETS_NAME"));
			tFixedAssetsPO.setFixedAssetsType(dynaBeanMap.get("FIXED_ASSETS_TYPE")==null?null:(String)dynaBeanMap.get("FIXED_ASSETS_TYPE"));
			tFixedAssetsPO.setBrand(dynaBeanMap.get("BRAND")==null?null:(String)dynaBeanMap.get("BRAND"));
			tFixedAssetsPO.setFixedAssetsNature(dynaBeanMap.get("FIXED_ASSETS_NATURE")==null?null:(String)dynaBeanMap.get("FIXED_ASSETS_NATURE"));
			tFixedAssetsPO.setRemark(dynaBeanMap.get("REMARK")==null?null:(String)dynaBeanMap.get("REMARK"));
			tFixedAssetsPO.setUpdateDate(DateUtils.TimestampToDate(dynaBeanMap.get("UPDATE_DATE")));
			tFixedAssetsPO.setUpdateBy(dynaBeanMap.get("UPDATE_BY")==null?null:(String)dynaBeanMap.get("UPDATE_BY"));
			tFixedAssetsPO.setCreateDate(DateUtils.TimestampToDate(dynaBeanMap.get("CREATE_DATE")));
			tFixedAssetsPO.setCreateBy(dynaBeanMap.get("CREATE_BY")==null?null:(String)dynaBeanMap.get("CREATE_BY"));
			tFixedAssetsPO.setIsValid(dynaBeanMap.get("IS_VALID")==null?null:(Integer)dynaBeanMap.get("IS_VALID"));
			return tFixedAssetsPO;
		}else{
			return null;
		}
	}
}
